var frameLoginTypeAttr = '0'
function frameLoginTypeChange (obj) {
  var _type = obj.getAttribute('data-user')
  if (_type === frameLoginTypeAttr) return
  frameLoginTypeAttr = _type
  document.getElementById('loginFrame').src = obj.getAttribute('data-url')
  obj.className += ' active'
  if (_type === '0') {
    obj.nextElementSibling.classList.remove('active')
  } else if (_type === '1') {
    obj.previousElementSibling.classList.remove('active')
  }
}

window['passportLogin'] = function (param) {
  try {
    if (param.isLogin) { return }
    var u = param.loginUrl || ''
    if (u.charAt(u.length - 1) === '/')u = u.substr(0, u.length - 1)
    if (u.indexOf('http') < 0)u = 'http://' + u
    if (u.indexOf('/passport/toLogin') < 0)u = u + '/passport/toLogin'
    u += '?type='
    var _html_ = '<style>\n' +
      '           .login-frame-box{border:none;position: absolute;top: ' + (param.top || '90px') + ';right:' + (param.right || '200px') + ';z-index:1000;width:310px;height:330px;overflow:hidden;background-color:rgba(255, 255, 255, 0.76);border-radius:6px;box-shadow: 0 0 18px 0 #bbbbbb;}\n' +
      // '           .login-frame-box-bg{display:block!important;position: absolute;left:0;right:0;top: ' + (param.top || "90px") + ';z-index:8;width:100%;height:330px;background:transparent!important;}' +
      '           .login-type-box{height:36px;overflow:hidden;margin:10px;border-radius:6px;border: 1px solid #0e8dfe;}\n' +
      '           .login-type-btn{float:left;width:50%;line-height:36px;text-align:center;font-size:16px;color:#333;cursor:pointer;}\n' +
      '           .login-type-btn:hover{background-color: #f5f5f5;}\n' +
      '           .login-type-btn.active{background-color:#0e8dfe;color:#fff;}\n' +
      '           #loginFrame{border:none;z-index:1000;width:100%;height: calc(100% - 36px);overflow:hidden;}\n' +
      '       </style>' +
      '       <div class="login-type-box">\n' +
      '            <div class="login-type-btn active" data-url="' + u + '0&url=' + param.webUrl + '" onclick="frameLoginTypeChange(this)" data-user="0">鐢ㄦ埛鐧诲綍</div>\n' +
      '            <div class="login-type-btn" data-url="' + u + '1&url=' + param.manageUrl + '" onclick="frameLoginTypeChange(this)" data-user="1">绠＄悊鍛樼櫥褰�</div>\n' +
      '        </div>\n' +
      '        <iframe src="' + u + '0&url=' + param.webUrl + '" id="loginFrame" frameborder="0"></iframe>'
    var f = document.createElement('div')
    f.className = 'login-frame-box'
    f.innerHTML = _html_
    var s = document.querySelector('body')
    s.appendChild(f)
    // 澧炲姞閫忔槑鑳屾櫙锛岃В鍐崇偣鍑绘梺杈圭殑杞挱鍥撅紝杈撳叆妗嗘棤娉曞け鍘荤劍鐐�
    // var bg = document.createElement("div");
    // bg.className = "login-frame-box-bg";
    // s.appendChild(bg);
  } catch (err) {
    console.error(err)
  }
}
